﻿using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using AdRotator.Common;
using AdRotator.Silverlight.AdProviders;

namespace AdRotator.XmlCreator.Silverlight
{
    class Program
    {
        static void Main(string[] args)
        {
            var settings = new XmlWriterSettings();
            settings.IndentChars = "\t";
            settings.Indent = true;

            using (var stream = File.Create("defaultAdSettings.xml"))
            {
                using (var xw = XmlTextWriter.Create(stream, settings))
                {
                    new XmlSerializer(typeof(AdSettings)).Serialize(xw, CreateDefaultAdSettings());
                }
                stream.Close();
            }
        }

        /// <summary>
        /// O
        /// </summary>
        /// <returns></returns>
        public static AdSettings CreateDefaultAdSettings()
        {
            var adSettings = new AdSettings()
            {
                AdCultures = new List<AdCulture>()
                {
                    new AdCulture()
                    {
                        Name = "en-US",
                        PubCenterAds = new List<PubCenterAd>()
                        {
                            new PubCenterAd(){AppId = "pubCenterApp1", AdUnitId="pubCenterAdUnit1", Probability = 50},    
                            new PubCenterAd(){AppId = "pubCenterApp1", AdUnitId="pubCenterAdUnit2", Probability = 50}    
                        }
                    },
                    new AdCulture()
                    {
                        Name = "en-GB",
                        PubCenterAds = new List<PubCenterAd>()
                        {
                            new PubCenterAd(){AppId = "pubCenterApp1", AdUnitId="pubCenterAdUnit1", Probability = 33},    
                            new PubCenterAd(){AppId = "pubCenterApp1", AdUnitId="pubCenterAdUnit2", Probability = 33}   
                        },
                        AdDuplexAds = new List<AdDuplexAd>()
                        {
                            new AdDuplexAd(){AppId = "adDuplexApp1", Probability = 25},
                            new AdDuplexAd(){AppId = "adDuplexApp2", Probability = 25},
                        }
                    },                
                    new AdCulture()
                    {
                        Name = AdSettings.DEFAULT_CULTURE,
                        PubCenterAds = new List<PubCenterAd>()
                        {
                            new PubCenterAd(){AppId = "pubCenterApp1", AdUnitId="pubCenterAdUnit1", Probability = 33}
                        },
                        AdDuplexAds = new List<AdDuplexAd>()
                        {
                            new AdDuplexAd(){AppId = "adDuplexApp1", Probability = 25}
                        }
                    },                    
                }
            };
            return adSettings;
        }
    }
}
